﻿@{
    var articles = new List<dynamic>();
    foreach(var i in Model.Items)
    {
        var t_article = (i.Translations as IEnumerable<dynamic>)
                .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                    JDM.Int32(Svc.Localization.Language.EntityID));
        if(t_article == null)
        {
            continue;
        }
        string title = JDM.String(t_article.Title);
        if(!String.IsNullOrWhiteSpace(title))
        {
            articles.Add(new
            {
                Entity = i,
                AZGroup = title.ToUpperInvariant().First(),
                Title = title
            });
        }
    }
}

<table class="unit-table article">
@if(articles.Any())
{
    var tmp = articles.GroupBy(x => x.AZGroup).OrderBy(x => x.Key).AsEnumerable();
    while(tmp.Any())
    {
        var g = tmp.Take(3);
        <thead>
            <tr>
            @foreach(var i in g)
            {
                <th>@i.Key</th>
            }
            </tr>
        </thead>
        <tbody>
            <tr>
            @foreach(var i in g)
            {
                <td>
                    <ul>
                    @foreach(var j in i)
                    {
                        <li class="unit article"><a href="@Url.Action(Loc.Act("Show").Set(new
                        {
                            id = JDM.Int32(j.Entity.EntityID)
                        }).Localized())">@j.Title</a></li>
                    }
                    </ul>
                </td>
            }
            </tr>
        </tbody>
        tmp = tmp.Skip(3);
    }
}
else
{
    <tr>
        <td class="empty"><span>@T(Res.In("Common").Of("Expr").Name("NoData"))</span></td>
    </tr>
}
</table>